package com.stylefeng.guns.modular.exOrder.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.ExOrder;
import com.stylefeng.guns.modular.exOrder.service.IExOrderService;

/**
 * 异常订单管理控制器
 *
 * @author fengshuonan
 * @Date 2018-10-12 13:38:30
 */
@Controller
@RequestMapping("/exOrder")
public class ExOrderController extends BaseController {

    private String PREFIX = "/exOrder/exOrder/";

    @Autowired
    private IExOrderService exOrderService;

    /**
     * 跳转到异常订单管理首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "exOrder.html";
    }

    /**
     * 跳转到添加异常订单管理
     */
    @RequestMapping("/exOrder_add")
    public String exOrderAdd() {
        return PREFIX + "exOrder_add.html";
    }

    /**
     * 跳转到修改异常订单管理
     */
    @RequestMapping("/exOrder_update/{exOrderId}")
    public String exOrderUpdate(@PathVariable Integer exOrderId, Model model) {
        ExOrder exOrder = exOrderService.selectById(exOrderId);
        model.addAttribute("item",exOrder);
        LogObjectHolder.me().set(exOrder);
        return PREFIX + "exOrder_edit.html";
    }

    /**
     * 获取异常订单管理列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return exOrderService.selectList(null);
    }

    /**
     * 新增异常订单管理
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(ExOrder exOrder) {
        exOrderService.insert(exOrder);
        return SUCCESS_TIP;
    }

    /**
     * 删除异常订单管理
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer exOrderId) {
        exOrderService.deleteById(exOrderId);
        return SUCCESS_TIP;
    }

    /**
     * 修改异常订单管理
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(ExOrder exOrder) {
        exOrderService.updateById(exOrder);
        return SUCCESS_TIP;
    }

    /**
     * 异常订单管理详情
     */
    @RequestMapping(value = "/detail/{exOrderId}")
    @ResponseBody
    public Object detail(@PathVariable("exOrderId") Integer exOrderId) {
        return exOrderService.selectById(exOrderId);
    }
}
